package multicast

import (
	"bytes"
	"net"

	"gitee.com/sillyman/netutils/macaddr"

	"gitee.com/sillyman/pcaphelper/pktbuilder"
)

// BuildMulticastWithVLAN 构造组播报文
func BuildMulticastWithVLAN(src net.HardwareAddr, vID uint16, srcIP, dstIP net.IP, srcPort, dstPort uint16) []byte {
	if dstIP == nil || !dstIP.IsMulticast() {
		return nil
	}

	return pktbuilder.BuildingEtherPkt(src, macaddr.MappingMulticastIP4ToMAC(dstIP),
		pktbuilder.GenLayerThatDot1Q(0, vID,
			pktbuilder.GenLayerThatIP4(srcIP, dstIP,
				pktbuilder.GenLayerThatUDP(srcPort, dstPort, bytes.Repeat([]byte{0xA8}, 128)),
			),
		),
	)
}
